package com.shopping.service.impl;

import java.util.HashMap;
import java.util.Map;

import com.shopping.bean.User;
import com.shopping.dao.UserDao;
import com.shopping.dao.impl.UserDaoImpl;
import com.shopping.service.UserService;

public class UserServiceImpl implements UserService {

	UserDao userDao = new UserDaoImpl();

	@Override
	public int addUser(User user) {
		User u = userDao.selectUser(user.getUserName());
		if(u == null) {
			return userDao.insertUser(user);
		}else {
			return -1;
		}
		
	}
	
	@Override
	public Map<String, Object> userLogin(String username,String password) {
		Map<String,Object> map = new HashMap();
		User user = userDao.selectUser(username, password);
		if(user != null) {
			map.put("loginUser", user);
		}else {
			user = userDao.selectUser(username);
			if(user != null) {
				map.put("errorCode","密码错误");
			}else {
				map.put("errorCode","用户名不存在");
			}
		}
		return map;
	}

	@Override
	public int getUserId(String username, String password) {
		return userDao.selectUserId(username, password);
	}

	@Override
	public int updateUserMsg(User user) {
		return userDao.updateUserMassage(user);
	}

}
